package com.zbiti.anvil.webservice.gateway.samples.impl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.zbiti.anvil.webservice.gateway.samples.DemoWebService;
import com.zbiti.anvil.webservice.gateway.samples.domain.DemoParamDomain;
import com.zbiti.sdk.common.utils.JsonUtils;

import java.util.List;
import java.util.Map;

/**
 * 示例Web服务接口实现
 *
 * @author Fanyc
 * @date 2022-01-11 13:59
 */
public class DemoWebServiceImpl implements DemoWebService {
    /**
     * 演示服务接口1
     *
     * @return 输出参数
     */
    @Override
    public String execute1(String param1, List<Integer> param2, Map<String, Long> param3, String param4) {
        return String.format("execute1: hello param1=%s, param2=%s and param3=%s,param4=%s", param1, param2, param3, param4);
    }

    /**
     * 演示服务接口2
     *
     * @return 输出参数
     */
    @Override
    public String execute2(String param1, List<Integer> param2, Map<String, Object> param3, Float param4) {
        return String.format("execute2: hello param1=%s,param2=%s,param3=%s,param4=%s", param1, param2, param3, param4);
    }

    /**
     * 演示服务接口3
     *
     * @return 输出参数
     */
    @Override
    public String execute3(DemoParamDomain domain) {
        try {
            return JsonUtils.toJSONString(domain);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return "null";
    }

    /**
     * 演示服务接口4
     */
    @Override
    public String execute4(List<DemoParamDomain> domain) {
        try {
            return JsonUtils.toJSONString(domain);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return "null";
    }

    /**
     * 演示服务接口5:不校验
     */
    @Override
    public String execute5(String param) {
        return param;
    }

    /**
     * 演示服务接口6:不校验
     */
    @Override
    public String execute6(DemoParamDomain domain) {
        try {
            return JsonUtils.toJSONString(domain);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return "null";
    }
}
